﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace NWN.GDY.Service.Entity
{
    [DataContract]
    public class Table
    {
        //编号
        [DataMember]
        public string TableGUID { set; get; }
        //起始时间
        [DataMember]
        public DateTime StartTime { set; get; }
        //结束时间
        [DataMember]
        public DateTime EndTime { set; get; }
        //局数
        [DataMember]
        public int RoundCount { set; get; }
        //聊天记录
        [DataMember]
        public List<ChatRecord> RecordList { set; get; }
        //进入口令
        [DataMember]
        public string Passport { set; get; }
        //人员列表
        [DataMember]
        public List<Player> Players { set; get; }
        //创建人
        [DataMember]
        public Player Creator { set; get; }
        //桌名
        public string TableName { set; get; }
        //坐位
        public List<Seat> Seats { set; get; }
        //是否游戏中
        public bool GameProcessing { set; get; }
        //当前局
        public Round round { set; get; }

        public Table CloneSimpleCopy()
        {
            return CloneSimpleCopy(0, 0);
        }

        public Table CloneSimpleCopy(int recordid, int rounddetailid)
        {
            Table tOut = new Table()
            {
                TableGUID = this.TableGUID,
                RoundCount = this.RoundCount,
                RecordList = new List<ChatRecord>(),
                Players = this.Players,
                TableName = this.TableName,
                GameProcessing = this.GameProcessing,
                round = this.round.CloneSimpleCopy(rounddetailid),
            };
            for (int i = recordid; i < this.RecordList.Count; i++)
            {
                RecordList.Add(this.RecordList[i]);
            }
            return tOut;
        }

        
        public Table(string guid, string nick, string uid, string tablename)
        {
            TableGUID = guid;
            TableName = tablename;
            Creator = new Player() { NickName = nick, UID = uid, };
            initTable();
            Players.Add(Creator);
        }

        public Table()
        {
            initTable();
        }

        public Table(string guid, string passport, string nick, string uid, string tablename)
        {
            TableGUID = guid;
            TableName = tablename;
            Creator = new Player() { NickName = nick, UID = uid, };
            Passport = passport;
            initTable();
            Players.Add(Creator);
        }

        void initTable()
        {
            StartTime = System.DateTime.Now;
            EndTime = System.DateTime.Now;
            RoundCount = 0;
            RecordList = new List<ChatRecord>();
            Players = new List<Player>();
            Seats = new List<Seat>();
            //赋上最大值八个位子
            for (int i = 0; i < 8; i++)
            {
                Seat st = new Seat();
                st.Disabled = false;
                st.SeatID = i;
                Seats.Add(st);
            }
            //占掉第一个位子
            Seats[0].OccupiedPlayer = Creator;
            Creator.SitSeat = Seats[0].SeatID;
            GameProcessing = false;
        }
    }
}
